//
//  TurnOverItemizedTableViewController.m
//  EasyToTesco2.0
//
//  Created by 袖手旁觀 on 16/6/23.
//  Copyright © 2016年 EasyToTesco. All rights reserved.
//

#import "TurnOverItemizedTableViewController.h"
#import "TurnOverItemizedCell.h"

@interface TurnOverItemizedTableViewController ()
{
    UIImageView *noDrawImage;
}

@property (nonatomic,strong)NSArray *turnOverItemizedArray;

@end


static NSString *const reuseIdentifier = @"TurnOverItemizedIdentifier";
@implementation TurnOverItemizedTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.tableFooterView = [[UIView alloc] init];
    
    self.tableView.backgroundColor = BACKGROUND_COLOR;
    [self.tableView registerNib:[UINib nibWithNibName:@"TurnOverItemizedCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:reuseIdentifier];
    self.title = @"营业额结算明细";
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    [self loadTurnOverItemizedData];
    
    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        
        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, -25, 0, 0)];
        
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.turnOverItemizedArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    TurnOverItemizedCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];
    
    if (!cell) {
        cell = [[TurnOverItemizedCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:reuseIdentifier];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    
    NSDictionary *dataDict = self.turnOverItemizedArray[indexPath.row];
    
    cell.timeLabel.text = [NSString stringWithFormat:@"%@",dataDict[@"addtime"]];
    cell.nameLabel.text = [NSString stringWithFormat:@"姓名: %@",dataDict[@"zhenming"]];
    cell.currentLabel.text = [NSString stringWithFormat:@"流水号: %@",dataDict[@"dxh"]];
    cell.numberLabel.text = [NSString stringWithFormat:@"金额: %@",dataDict[@"jine"]];
    
    if ([dataDict[@"ck"] isEqual:@(0)]) {
        cell.statusLabel.text = @"状态: 未处理";
    }else if ([dataDict[@"ck"] isEqual:@(1)]){
        cell.statusLabel.text = @"状态: 成功";
    }else if ([dataDict[@"ck"] isEqual:@(2)]){
        cell.statusLabel.text = @"状态: 失败";
    }else{
        cell.statusLabel.text = @"状态: 未处理";
    }
    
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 143;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 5;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.01;
}

- (NSArray *)turnOverItemizedArray {
    if (!_turnOverItemizedArray) {
        _turnOverItemizedArray = [NSArray array];
    }
    return _turnOverItemizedArray;
}

- (void)loadTurnOverItemizedData {
    [[NetWorkSharedTools sharedNetWorkTools] objectWithURLDict:@{@"username":USERNAME} AndMenthodName:@"/api/Finance/turnoverClearingList" completeBlock:^(id object) {
        
        NSLog(@"%@",object);
        
        if (JudgeBackDataCode) {
            
            self.turnOverItemizedArray = [object objectForKey:@"data"];
        }else{
            
            //暂无地址(图)
            noDrawImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"noTurnOverItemized"]];
            [self.view addSubview:noDrawImage];
            
            [noDrawImage mas_makeConstraints:^(MASConstraintMaker *make) {
                make.centerX.equalTo(self.view.mas_centerX);
                make.centerY.equalTo(self.view.mas_centerY).offset(-HEIGHT/10);
                make.width.mas_equalTo(WIDTH/2);
                make.height.mas_equalTo(HEIGHT/4);
            }];
        }
        
        [self.tableView reloadData];
        
    }];
}
@end
